<?php
/*
+-----------------------------------------------------------------------------+
| $Id: attach.php 2010-05-24 12:37:44Z Bleakwind $
| Download attach
| Copyright (c) 2003-2010 Bleakwind (www.weaverdream.com)
| http://www.weaverdream.com/
| Release under the GNU Lesser General Public License Version 3 (LGPLv3):
|   http://www.gnu.org/licenses/lgpl.html
+-----------------------------------------------------------------------------+
*/

if (!defined( 'ENTRY_INDEX')){
    echo "<h1>Forbidden</h1><p>You don't have permission to access on this server.</p>";
    exit;
}

if (!preg_match("/^[1-9][0-9]{0,10}$/", $sys->get['attach_id'])) {
    $sys->prompt("failed",$LANGUAGE['s']['attach']['attach_id_empty']."<!-- attach_id_empty -->");
} else {
    $sql = "SELECT content_attach.*
            FROM ".DB_TABLE_CONTENT_ATTACH." content_attach
            WHERE content_attach.id=".$sys->get['attach_id'];
    $result = &$db->Execute($sql);
    if (!$result) {
        $sys->prompt("failed",$db->ErrorMsg()."<!-- ErrorMsg -->");
    } else {
        if ($result->EOF) {
            $sys->prompt("failed",$LANGUAGE['s']['attach']['attach_not_exist']."<!-- attach_not_exist -->");
        } else {
            $attach_info = array(
                    'id'            => $result->fields['id'],
                    'dir'           => $result->fields['dir'],
                    'filename'      => $result->fields['filename'],
                    'brief'         => $result->fields['brief'],
                    'watermark'     => $result->fields['watermark'],
                    'key_id'        => $result->fields['key_id'],
                    'admin_id'      => $result->fields['admin_id'],
                    'time'          => $result->fields['time'],
                    'down'          => $result->fields['down'],
            );
            if (!preg_match("/^[1-9][0-9]{0,10}$/", $attach_info['id'])) {
                $sys->prompt("failed",$LANGUAGE['s']['attach']['attach_id_not_exist']."<!-- attach_id_not_exist -->");
            } else {

                $sql_data = array(
                    "down" => "down+1",
                );
                $result = func::db_update(DB_TABLE_CONTENT_ATTACH, $sql_data, "id='".$attach_info['id']."'");

                $CONFIGURE['common']['if_output_template'] = "0";
                include_once './lib/class/bwanydown.class.php';
                $bwad = new bwanydown();
                $bwad->download("./".$SETTING['dir_content_attach']."/".$attach_info['dir'].$attach_info['filename'], $attach_info['brief']);
            }
        }
    }
}
$public_var['page_place'][] = $LANGUAGE['s']['attach']['page_place'];
?>
